package com.bright.ghj.overt.manager.impl;

import com.bright.ghj.overt.converter.PublicInfoMasterTableConverter;
import com.bright.ghj.overt.manager.PublicInfoMasterTableManager;
import com.bright.ghj.overt.pojo.dto.PublicInfoMasterTableDTO;
import com.bright.ghj.overt.pojo.po.second.PublicInfoMasterTable;
import com.bright.ghj.overt.repository.second.PublicInfoMasterTableRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * @author Tz
 * @date 2024/01/26 15:03
 * @Description 党廉公开主表信息 Manager 实现
 */
@Component
@RequiredArgsConstructor
public class PublicInfoMasterTableManagerImpl implements PublicInfoMasterTableManager {

    private final PublicInfoMasterTableConverter publicInfoMasterTableConverter;
    private final PublicInfoMasterTableRepository publicInfoMasterTableRepository;

    /**
     * 保存党廉公开主表信息
     * @param publicInfoMasterTableDTO 党廉公开主表信息DTO
     * @return                         保存成功后的党廉公开主表信息DTO
     */
    @Override
    public PublicInfoMasterTableDTO save(PublicInfoMasterTableDTO publicInfoMasterTableDTO) {
        PublicInfoMasterTable publicInfoMasterTable = publicInfoMasterTableConverter.dtoConvertPO(publicInfoMasterTableDTO);
        PublicInfoMasterTable save = publicInfoMasterTableRepository.save(publicInfoMasterTable);
        return publicInfoMasterTableConverter.poConvertDTO(save);
    }

    /**
     * 根据条件党廉公开主表信息
     *
     * @param messageSendingTime 公开表公开的时间列表
     * @param dwbm               单位编码
     * @return                   返回党廉公开主表信息列表
     */
    @Override
    public List<PublicInfoMasterTableDTO> listPublicInfoMasterTable(List<String> messageSendingTime, String dwbm) {
        List<PublicInfoMasterTable> publicInfoMasterTables = publicInfoMasterTableRepository.listPublicInfoMasterTable(messageSendingTime, dwbm);
        return publicInfoMasterTableConverter.poConvertDTO(publicInfoMasterTables);
    }

    /**
     * 保存党廉公开主表信息
     *
     * @param cjbh 党廉公开主表信息的采集编号
     * @return     党廉公开主表信息DTO
     */
    @Override
    public PublicInfoMasterTableDTO findById(String cjbh) {
        Optional<PublicInfoMasterTable> optional = publicInfoMasterTableRepository.findById(cjbh);
        if (optional.isPresent()) {
            PublicInfoMasterTable publicInfoMasterTable = optional.get();
            return publicInfoMasterTableConverter.poConvertDTO(publicInfoMasterTable);
        }
        return null;
    }
}
